#!/usr/bin/perl
# Version 0.2.1

$testcase = "nbr_state";

# 1 = PASS
# 2 = FAIL
# 3 = INCONCLUSIVE
$verdict = 3;

$dumpfile = "$testcase.dump";
$logfile = "$testcase.log";

if ($#ARGV ne 1) {
        print("Usage: $testcase.pl dump_file log_file");
        exit 1;
}

$dumpfile = $ARGV[0];
$logfile = $ARGV[1];

#------------------------------------------------------------------------------
$verdict_1 = 3; # does the rut send an ls_ack
$verdict_2 = 3; # does the rut send an ls_upd

# Open the dumpfile
$success = 1;
open(DUMPFILE, $dumpfile) or $success = 0;

if ($success eq 1) {
	
	$verdict_1 = 1;
	$verdict_2 = 1;
			
	while(<DUMPFILE>) {
		
		if(/0\.0\.0\.1 > (.*) OSPFv2-ls_ack/) {
			# bad thing...
			$verdict_1 = 2;
		}
		
		if(/0\.0\.0\.1 > (.*) OSPFv2-ls_upd/) {
			# also a bad thing...
			$verdict_2 = 2;
		}	
	}
	
	close(DUMPFILE);
}

if($verdict_1 eq 1) {
	print("RUT does not acknowledge early ls_update. Test PASSED.\n");
} elsif ($verdict_1 eq 2) {
	print("RUT acknowledges ls_update in state EXSTART. Test FAILED.\n");
} else {
	print("Cannot evaluate results. Test INCONCLUSIVE.\n");
}

if($verdict_2 eq 1) {
	print("RUT ignores ls_request in state EXSTART. Test PASSED.\n");
} elsif ($verdict_2 eq 2) {
	print("RUT answers to request in state EXSTART. Test FAILED.\n");
} else {
	print("Cannot evaluate results. Test INCONCLUSIVE.\n");
}

$verdict = $verdict_1;
if ($verdict_2 ne $verdict) {
	if($verdict_2 eq 2) {
		$verdict = 2;
	} elsif ($verdict_2 eq 3) {
		if($verdict ne 2) {
			$verdict = 3;
		}
	}	
}

#------------------------------------------------------------------------------
print("### VERDICT for $testcase: ");

if ($verdict eq 1) { 
        print("PASS"); 
} elsif ($verdict eq 2) {
        print("FAIL");
} else {
        print("INCONCLUSIVE");
}

print(" ###\n");